//; ---------------------------------------------------------------------------
//; Object 21 - SCORE, TIME, RINGS
//; ---------------------------------------------------------------------------
#define id_HUD 0x21
#include "hud.h"

object *obj;

void (*HUD_Index[2])() = { HUD_Main, HUD_Flash };

void HUD(object *_obj)
{
    obj = _obj;

    //moveq	#0,d0
    //move.b	obRoutine(a0),d0
    byte routine = obj->Routine/2;

    //move.w	HUD_Index(pc,d0.w),d1
    //jmp	HUD_Index(pc,d1.w)
    (*HUD_Index[routine])();
}

void HUD_Main()
{
    //HUD_Main:	; Routine 0
    //addq.b	#2,obRoutine(a0)
    obj->Routine = obj->Routine + 2;

    //move.w	#$90,obX(a0)
    obj->X = 0x90;

    //move.w	#$108,obScreenY(a0)
    obj->ScreenY = 0x180;

    //move.l	#Map_HUD,obMap(a0)
    obj->Map = Map_HUD;

    //move.w	#$6CA,obGfx(a0)
    obj->Gfx = 0x6CA;

    //move.b	#0,obRender(a0)
    obj->Render = 0;
 
    //move.b	#0,obPriority(a0)
    obj->Priority = 0;

    HUD_Flash();
}
    

void HUD_Flash()
{
    //HUD_Flash:	; Routine 2
    //tst.w	(v_rings).w	; do you have any rings?
    //beq.s	@norings	; if not, branch
    if (v_rings != 0)
    {
        //clr.b	obFrame(a0)	; make all counters yellow
        obj->Frame = 0;

	//jmp	DisplaySprite
        DisplaySprite(obj);
    }
    else
    {
        //; ===========================================================================
        //@norings:
	//moveq	#0,d0
        word frame = 0;

	//btst	#3,(v_framebyte).w
        //bne.s	@display
        if ((v_framebyte & 8) == 8)
        {
	    //addq.w	#1,d0		; make ring counter flash red
            frame = frame + 1;

	    //cmpi.b	#9,(v_timemin).w ; have	9 minutes elapsed?
            //bne.s	@display	; if not, branch
            if (v_timemin == 9)
            {
	        //addq.w	#2,d0		; make time counter flash red
                frame = frame + 2;

	    }
        }
        
        //@display:
	//move.b	d0,obFrame(a0)
        obj->Frame = frame;

	//jmp	DisplaySprite
        DisplaySprite(obj);
    }
}
